//
//  SESyndromeCell.m
//  kuaiyi
//
//  Created by Alphts on 16/7/7.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SESyndromeCell.h"
#import "SESyndromeDTO.h"

@interface SESyndromeCell ()

@property (nonatomic, weak) UIButton *leftButton;

@end


@implementation SESyndromeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        [self setupUI];
        
    }
    
    return self;
}

- (void)setupUI{
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.leftButton = leftButton;
    
    
    [leftButton setTitle:@" 已订阅 " forState:UIControlStateNormal];
    
    [leftButton sizeToFit];
    
    [leftButton setTitle:@" 订阅 " forState:UIControlStateNormal];
    
    [leftButton setBackgroundColor:kThemeColor];
    
    [leftButton addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:leftButton];
    
    self.accessoryView = leftButton;
}


- (void)didClickBtn:(UIButton *)sender{
    
    if (self.cellBlock) {
        self.cellBlock();
    }
 
}


- (void)setModel:(SESyndromeDTO *)model{
    
    _model = model;
    
    self.textLabel.text = model.title;
    
    if (model.isSelected) {
        
        [self.leftButton setTitle:@" 已订阅 " forState:UIControlStateNormal];
        
        [self.leftButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    }else{
        [self.leftButton setTitle:@" 订阅 " forState:UIControlStateNormal];
        
        [self.leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    
}

//选中cell的accessoryView不被cell的选中颜色覆盖
- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.leftButton setBackgroundColor:kThemeColor];
}


@end
